/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package controlador;

import java.io.IOException;
import java.io.PrintWriter;
import java.util.Properties;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.Properties;
import modelo.*;
/**
 *
 * @author manuell2
 */
public class main_ser extends HttpServlet {

    /** 
     * Processes requests for both HTTP <code>GET</code> and <code>POST</code> methods.
     * @param request servlet request
     * @param response servlet response
     * @throws ServletException if a servlet-specific error occurs
     * @throws IOException if an I/O error occurs
     */
    PrintWriter out;
    HttpServletRequest request;
    HttpServletResponse response;

    protected void processRequest(HttpServletRequest request, HttpServletResponse response)
   throws ServletException, IOException {
        this.out = out;
        this.request = request;
        this.response = response;
        
        response.setContentType("text/html;charset=UTF-8");
        out = response.getWriter();
        try {
   //Esta parte es para que siempre se vea los botones y cuadros de texto del principio
   //parece que no es necesario que la estructura del html sea estandar...

   out.println("<html>");
   out.println("<head>");
   out.println("<title>____________________________________________________</title>");  
   out.println("</head>");
   out.println("<body>");
   //out.println("<h1>Servlet main_ser at " + request.getContextPath () + "</h1>");
   
/*<input type="text" name="txt_nombre" value="nombre" />          
<input type="file" name="file_select" value="" />*/
   
  // Para saber que boton he pulsado, el unico que no se pone a null es el que esta pulsado
   if (request.getParameter("b_buscar")!=null){
        out.println("<h1>"+request.getParameter("b_buscar") + "</h1>");
        muestra_parametros();
        
   }
   if (request.getParameter("b_crear")!=null){
        out.println("<h1>"+request.getParameter("b_crear") + "</h1>");
         muestra_parametros();
   }
   if (request.getParameter("b_eliminar")!=null){
      out.println("<h1>"+request.getParameter("b_eliminar") + "</h1>");  
       muestra_parametros();
   }
   //.........................................
   
   out.println("</body>");
   out.println("</html>");
        } finally {   
   out.close();
        }
    }
//==============================================================================
    public String muestra_parametros(){
    out.println("<h1>"+request.getParameter("txt_nombre") + "</h1>");
    out.println("<h1>"+request.getParameter("file_select") + "</h1>");
        return null;
    }
//=============================================================================
//==============================================================================  
//==============================================================================

//..............................................................................
    // <editor-fold defaultstate="collapsed" desc="HttpServlet methods. Click on the + sign on the left to edit the code.">
    /** 
     * Handles the HTTP <code>GET</code> method.
     * @param request servlet request
     * @param response servlet response
     * @throws ServletException if a servlet-specific error occurs
     * @throws IOException if an I/O error occurs
     */
    @Override
    protected void doGet(HttpServletRequest request, HttpServletResponse response)
   throws ServletException, IOException {
        processRequest(request, response);
    }

    /** 
     * Handles the HTTP <code>POST</code> method.
     * @param request servlet request
     * @param response servlet response
     * @throws ServletException if a servlet-specific error occurs
     * @throws IOException if an I/O error occurs
     */
    @Override
    protected void doPost(HttpServletRequest request, HttpServletResponse response)
   throws ServletException, IOException {
        processRequest(request, response);
    }

    /** 
     * Returns a short description of the servlet.
     * @return a String containing servlet description
     */
    @Override
    public String getServletInfo() {
        return "Short description";
    }// </editor-fold>
}
